

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>积分商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <#include "../../include/layui.ftl" />
    <#include "../../include/pTable.ftl" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form id="queryForm">
                <input type="hidden" id="className" name="className" value="${className!}" />
                <input type="hidden" id="modleName" name="modleName" value="${modleName!}" />
                <input type="hidden"  name="createrId" value="${SESSION_USER.user.id!}" />
                <input type="hidden" name="createrId_searchType" value="eq">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">产品名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="productName" placeholder="请输入" autocomplete="off" class="layui-input">
                            <input type="hidden" name="productName_searchType" value="like">
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">

            <table id="lay-table" lay-filter="lay-table"></table>
            <script type="text/html" id="toolbar">
            </script>
        </div>

    </div>
</div>

<script>
    /**/
</script>

<script>
    var layer = null,table = null;
    var $ = null;
    function exchange(data){
        layer.confirm('确定兑换吗?',{icon: 3,title:'提示'}, function (index) {
            $.ajax({
                url:"/console/integral/order/add", //请求后台
                dataType:"json",
                type:"get",
                async:true,
                data:{"productId":data},
                success:function(res){
                    if(res.code == 0 ){
                        layer.msg('兑换成功,请等待发货', {icon: 1});
                        // 刷新页面
                        table.reload("lay-table");
                        //location.reload();
                    }if(res.code == 400 ){
                        layer.msg(res.msg, {icon: 2});
                    }if(res.code == -1){
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
            layer.close(index);
        })

    }

    layui.config({
        base: '${path}/plug-in/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','tables','layers','view','excels','upload'],function () {
        var tables = layui.tables,
            view = layui.view,
            layers = layui.layers,
            excels = layui.excels,
            upload = layui.upload,
            $ = layui.$;
        layer = layui.layer;
        table = layui.table;
        $(document).on('click','#duihuan',function(data){
            console.info(data.id)
        });


        var parmer = {
            url:'/console/integral/product/allList',
            defaultToolbar: ['filter',{
                title: '导出' //标题
                ,layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
                ,icon: 'layui-icon-export' //图标类名
            }],
            where:{sort : 'create_time',order:'desc',createrId:"${SESSION_USER.user.id!}",createrId_searchType:"eq" },
            cols:[[
                {field:"productName",width:90,title:"产品名称"}
                ,{field:"integral",width:120,title:"产品兑换积分"}
                ,{field:"type",width:90,title:"产品类型"}
                ,{field:"productDescribe",width:180,title:"产品简介"}
                ,{field:"state",width:90,title:"产品状态",templet:function(d){
                        var valArr = ['有效', '无效'];
                        return valArr[d.state];
                    }}
                ,{field:"startTime",width:180,title:"产品开始兑换时间"}
                ,{field:"endTime",width:180,title:"产品结束兑换时间"}
                ,{field:"stock",width:90,title:"产品库存"}
                ,{field:"productIcon",width:'10%',title:"产品图片",templet: function(d){
                        return '<a href="javascript:void(0);" onclick="viewImg(\''+d.productIcon+'\')">点击查看</a>';
                    }}
                ,{fixed: '', title:'操作',width:120,templet:function (d) {
                    return "<a class=\"layui-btn layui-btn-danger layui-btn-xs\" onclick='exchange(\""+d.id+"\")' >兑换</a>";
                    } }
            ]]
        };
        var $tables = tables.renderTable(parmer);

        //头工具栏事件
        table.on('toolbar(lay-table)', function(obj){
            switch(obj.event){
                case '01':
                    layers.add({
                        area:['700px', '750px']
                    });
                    break;
                case '02':
                    layers.edit({
                        area:['700px', '750px'],
                        data: p.data
                    });
                    break;
                case '03':
                    layers.delete({url:'/console/com.fs.common.pojo.IntegralProduct/delete',data:p.data});
                    break;
                case '04':
                    layers.view({
                        area:['700px', '760px'],
                        data: p.data
                    });
                    break;
                case '05':
                    var where = $("#queryForm").serializeObject();
                    where = $.extend({}, $tables.config.where, where);
                    $tables.reload({
                        where: where,
                        text: {none: '暂无数据！'}
                    });
                    break;
            };
        });


    });
    function viewImg(url) {
        if(typeof url == "undefined" || url == null || url == ""){
            layer.msg('没有图片');
        }else{
            var urlJpg = url.split('/');
            var data = {
                "title": "查看图片", //相册标题
                "id": 123, //相册id
                "start": 0, //初始显示的图片序号，默认0
                "data": [   //相册包含的图片，数组格式
                    {
                        "alt": "图片",
                        "pid": 666, //图片id
                        "src": "http://localhost:9001/" + urlJpg[2], //原图地址
                        "thumb": "http://localhost:9001/" + urlJpg[2] //缩略图地址
                    }
                ]
            }
            layer.photos({
                photos: data //格式见API文档手册页
            });
        }

    }
</script>

</body>
</html>